package com.jxw.gk;

import android.content.Context;
import android.content.SharedPreferences;
import com.jxw.engine.platsign.MainActivity;
import com.jxw.launcher.MyApp;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

/* loaded from: classes.dex */
public class SPUtils {
    private static final String KEY_SERIES = "series";
    private static final String KEY_TOKEN = "token";
    private static final String KEY_TOKEN_SAVE_TIME = "token_save_time";

    public static void put(Context context, String str, Object obj) {
        SharedPreferences.Editor edit = context.getSharedPreferences(MainActivity.PREFERENCE, 0).edit();
        if (obj instanceof String) {
            edit.putString(str, (String) obj);
        } else if (obj instanceof Integer) {
            edit.putInt(str, ((Integer) obj).intValue());
        } else if (obj instanceof Boolean) {
            edit.putBoolean(str, ((Boolean) obj).booleanValue());
        } else if (obj instanceof Float) {
            edit.putFloat(str, ((Float) obj).floatValue());
        } else if (obj instanceof Long) {
            edit.putLong(str, ((Long) obj).longValue());
        } else {
            edit.putString(str, obj.toString());
        }
        SharedPreferencesCompat.apply(edit);
    }

    public static void putConfig(Context context, String str, Object obj) {
        SharedPreferences.Editor edit = context.getSharedPreferences(MainActivity.PREFERENCE, 0).edit();
        if (obj instanceof String) {
            edit.putString(str, (String) obj);
        } else if (obj instanceof Integer) {
            edit.putInt(str, ((Integer) obj).intValue());
        } else if (obj instanceof Boolean) {
            edit.putBoolean(str, ((Boolean) obj).booleanValue());
        } else if (obj instanceof Float) {
            edit.putFloat(str, ((Float) obj).floatValue());
        } else if (obj instanceof Long) {
            edit.putLong(str, ((Long) obj).longValue());
        } else {
            edit.putString(str, obj.toString());
        }
        SharedPreferencesCompat.apply(edit);
    }

    public static boolean getBoolean(Context context, String str, boolean z) {
        return context.getSharedPreferences(MainActivity.PREFERENCE, 0).getBoolean(str, z);
    }

    public static int getInt(Context context, String str, int i) {
        return context.getSharedPreferences(MainActivity.PREFERENCE, 0).getInt(str, i);
    }

    public static void setBoolean(Context context, String str, boolean z) {
        context.getSharedPreferences(MainActivity.PREFERENCE, 0).edit().putBoolean(str, z).commit();
    }

    public static void putLong(Context context, String str, long j) {
        context.getSharedPreferences(MainActivity.PREFERENCE, 0).edit().putLong(str, j).commit();
    }

    public static long getLong(Context context, String str, long j) {
        return context.getSharedPreferences(MainActivity.PREFERENCE, 0).getLong(str, j);
    }

    public static Object get(Context context, String str, Object obj) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(MainActivity.PREFERENCE, 0);
        if (obj instanceof String) {
            return sharedPreferences.getString(str, (String) obj);
        }
        if (obj instanceof Integer) {
            return Integer.valueOf(sharedPreferences.getInt(str, ((Integer) obj).intValue()));
        }
        if (obj instanceof Boolean) {
            return Boolean.valueOf(sharedPreferences.getBoolean(str, ((Boolean) obj).booleanValue()));
        }
        if (obj instanceof Float) {
            return Float.valueOf(sharedPreferences.getFloat(str, ((Float) obj).floatValue()));
        }
        if (obj instanceof Long) {
            return Long.valueOf(sharedPreferences.getLong(str, ((Long) obj).longValue()));
        }
        return null;
    }

    public static void remove(Context context, String str) {
        SharedPreferences.Editor edit = context.getSharedPreferences(MainActivity.PREFERENCE, 0).edit();
        edit.remove(str);
        SharedPreferencesCompat.apply(edit);
    }

    public static void clear(Context context) {
        SharedPreferences.Editor edit = context.getSharedPreferences(MainActivity.PREFERENCE, 0).edit();
        edit.clear();
        SharedPreferencesCompat.apply(edit);
    }

    public static boolean contains(Context context, String str) {
        return context.getSharedPreferences(MainActivity.PREFERENCE, 0).contains(str);
    }

    public static Map<String, ?> getAll(Context context) {
        return context.getSharedPreferences(MainActivity.PREFERENCE, 0).getAll();
    }

    /* loaded from: classes.dex */
    private static class SharedPreferencesCompat {
        private static final Method sApplyMethod = findApplyMethod();

        private SharedPreferencesCompat() {
        }

        private static Method findApplyMethod() {
            try {
                return SharedPreferences.Editor.class.getMethod("apply", new Class[0]);
            } catch (NoSuchMethodException unused) {
                return null;
            }
        }

        public static void apply(SharedPreferences.Editor editor) {
            try {
                if (sApplyMethod != null) {
                    sApplyMethod.invoke(editor, new Object[0]);
                    return;
                }
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException unused) {
            }
            editor.commit();
        }
    }

    public static void saveString(String str, String str2) {
        SharedPreferences.Editor edit = MyApp.getInstance().getSharedPreferences(MainActivity.PREFERENCE, 0).edit();
        edit.putString(str, str2);
        edit.commit();
    }

    public static String getString(String str, String str2) {
        return MyApp.getInstance().getSharedPreferences(MainActivity.PREFERENCE, 0).getString(str, str2);
    }

    public static String getString(String str) {
        return MyApp.getInstance().getSharedPreferences(MainActivity.PREFERENCE, 0).getString(str, "");
    }

    public static long getTokenSaveTime() {
        return MyApp.getInstance().getSharedPreferences(MainActivity.PREFERENCE, 0).getLong(KEY_TOKEN_SAVE_TIME, 0L);
    }

    public static String getSeries() {
        return MyApp.getInstance().getSharedPreferences(MainActivity.PREFERENCE, 0).getString(KEY_SERIES, null);
    }

    public static String getToken() {
        return MyApp.getInstance().getSharedPreferences(MainActivity.PREFERENCE, 0).getString(KEY_TOKEN, null);
    }
}
